<template>
  <DaprPlusTable
    :table-title="$t('fsb.softwares.balance.list')"
    :entity="entity"
    :grid-options="gridOptions"
    :query-api="crudApi.getPage"
    @update:grid-api="onGridApiUpdate"
  />
</template>

<script lang="ts" setup>
import type { ExtendedVxeGridApi, VxeGridProps } from '#/adapter/vxe-table';
import { DaprPlusTable } from '#/components/daprplus';
import { createCrudApi } from '#/api/daprplus';
import type { IInDto, IOutDto, EntityInfo } from '#/utils/daprplus';
import { $t } from '#/locales';

const baseUrl = '/softwares/api/balance';
const crudApi = createCrudApi<BalanceInDto, BalanceOutDto>(baseUrl);

const entity: EntityInfo = {
  code: 'Balance',
  display: $t('fsb.softwares.balance.title'),
};

// 扩展配置
const gridOptions: VxeGridProps<BalanceOutDto> = {
  columns: [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '编号',
      sortable: true,
      width: 130,
    },
    {
      field: 'userName',
      title: '用户名',
      sortable: true,
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'nickName',
      title: '昵称',
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'value',
      title: '余额',
      align: 'right',
      minWidth: 120,
      formatter: ({ cellValue }) => cellValue.toFixed(2),
    },
    {
      field: 'bindValue',
      title: '绑定余额',
      align: 'right',
      minWidth: 120,
      formatter: ({ cellValue }) => cellValue.toFixed(2),
    },
    {
      field: 'recommendValue',
      title: '推广返利',
      align: 'right',
      minWidth: 120,
      formatter: ({ cellValue }) => cellValue.toFixed(2),
    },
    {
      field: 'createdTime',
      title: '创建时间',
      formatter: 'formatDateTime',
      width: 150,
    },
  ],
};

let gridApi: ExtendedVxeGridApi;

function onGridApiUpdate(api: ExtendedVxeGridApi) {
  gridApi = api;
}

export interface BalanceInDto extends IInDto {
  value: number;
  bindValue: number;
  recommendValue: number;
  isLocked: boolean;
  userId: number;
  userName: string;
  nickName: string;
}

export interface BalanceOutDto extends BalanceInDto, IOutDto {
  createdTime: string;
}
</script>

<style scoped></style>
